﻿@using Website.CRUDServices
@using Location = Website.Models.Domain.Location
@using Profile = Website.Models.Domain.Profile
@using Region = Website.Models.Domain.Region
@{
    this.ViewBag.Title = "Projektmøde";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Projects = this.ViewData["Projects"] as List<Project>;
    var Demonstrations = this.ViewData["Demonstrations"] as List<ProjectMeetingDemonstration>;
    var Funds = this.ViewData["Funds"] as List<Fund>;
    var Types = this.ViewData["Types"] as List<ProjectType>;
    var Roles = this.ViewData["Roles"] as List<ProjectMeetingRole>;
    var Groups = this.ViewData["Groups"] as List<Group>;
    var Profiles = this.ViewData["Profiles"] as Website.Models.ViewModels.ProfilesView;
    var Project = Model as ProjectMeeting;
    Guid otherId = Guid.Empty;

    // errorhandling
    var errorMsg = new HtmlString(string.Empty);
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }
    bool? isRandD = null;
    if (Types.Any(x => x.ID == Project.Status.Type))
    {
        isRandD = Types.Single(x => x.ID == Project.Status.Type).IsResearchAndDevelopment;
    }
}

@Html.Partial("~/Views/_Shared/LogView.cshtml", Project.ID)

<script type="text/javascript">
    //toggle script
    function toggle(id) {
        var allFields = new Array('NotStarted', 'Started', 'Completed');
        for (var i = 0; i < allFields.length; i++) {
            document.getElementById(allFields[i]).style.display = 'none';
        }

        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }

    function toggleRD(id) {
        var allFields = new Array('RAndD', 'NotRAndD');
        for (var i = 0; i < allFields.length; i++) {
            document.getElementById(allFields[i]).style.display = 'none';
        }

        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
</script>
<script>
    $(function () {
        $("#datepicker").datepicker();
        @if (Project.Status.StatusType == ProjectMeetingStatusType.NotStarted)
        {@Html.Raw("toggle('NotStarted');")}
        @if (Project.Status.StatusType == ProjectMeetingStatusType.Started)
        {@Html.Raw("toggle('Started');")}
        @if (Project.Status.StatusType == ProjectMeetingStatusType.Completed)
        {@Html.Raw("toggle('Completed');")}
        @if (isRandD.HasValue && !isRandD.Value)
        {@Html.Raw("toggleRD('NotRAndD')")}
        @if (isRandD.HasValue && isRandD.Value)
        {@Html.Raw("toggleRD('RAndD')")}
    });
</script>

@*// name*@
<fieldset class="chosenFields">
    <legend>Titel</legend>
    @Project.Name
</fieldset>


@*// ownerProjects chooser*@
<fieldset class="chosenFields">
    <legend>Alle projekter tilknyttet</legend>
    @foreach (Project proj in Projects.Where(x => (Project.OwnerProjects ?? new Guid[0]).Contains(x.ID)))
    {
        @proj.Name <br />
    }
</fieldset>


@*// date*@
<fieldset class="chosenFields">
    <legend>Dato</legend>
    @if (Project.Date.HasValue)
    {
        @Project.Date.Value.ToShortDateString()}
</fieldset>

@*// location*@
<fieldset class="chosenFields">
    <legend>Lokation</legend>
    @foreach (Location loc in Profiles.Locations.OrderBy(x => x.Name))
    {
        if (loc.ID == Project.LocationID)
        {
        @loc.Name <br />
        }
    }
</fieldset>


@*// national or international?*@
<fieldset class="chosenFields">
    <legend>Nationalt?</legend>
    <input type="radio" name="IsNational" value="National"@if (Project.IsNational)
                                                          {@Html.Raw(" checked=\"checked\"")} />Nationalt
        <input type="radio" name="IsNational" value="International"@if (!Project.IsNational)
                                                                   {@Html.Raw(" checked=\"checked\"")} />Internationalt
</fieldset>

@*// profiles chooser*@
<fieldset class="chosenFields">
    <legend>Deltagere</legend>
    @foreach (Profile prof in Profiles.Profiles.Where(x => (Project.Participants ?? new Guid[0]).Contains(x.ID)))
    {
        @prof.Name <br />
    }
</fieldset>

@*// Groups chooser
<fieldset class="chosenFields">
    <legend>Grupper</legend>
    @foreach (Group group in Groups.Where(x => (Project.Groups ?? new Guid[0]).Contains(x.ID)))
    {
        @group.Name <br />
    }
</fieldset>*@

@*// ********************StatusSelector**********************@
<fieldset class="chosenFields">
    <legend>Projektets status</legend>

    <label>
        <input type="radio" name="ProjectStatusType" value="SwitchStatusNotStarted" onclick=" toggle('NotStarted'); " 
                @if (Project.Status.StatusType == ProjectMeetingStatusType.NotStarted)
                {@Html.Raw("checked")}>Ikke startet</label>
    <label>
        <input type="radio" name="ProjectStatusType" value="SwitchStatusStarted" onclick=" toggle('Started'); " @if (Project.Status.StatusType == ProjectMeetingStatusType.Started)
                                                                                                                {@Html.Raw("checked")}>Startet</label>
    <label>
        <input type="radio" name="ProjectStatusType" value="SwitchStatusCompleted" onclick=" toggle('Completed'); " @if (Project.Status.StatusType == ProjectMeetingStatusType.Completed)
                                                                                                                    {@Html.Raw("checked")}>Færdigt</label>

</fieldset>
@*// ********************ProjectMeetingStatus**********************@

<div class="formEntry open_hidden" id="NotStarted">
    <br />
    <fieldset class="chosenFields">
        <legend>Ikke startet</legend>
        <!--demonstration chooser -->
        <fieldset class="chosenFields">
            <legend>Vejledt om</legend>

            @foreach (Fund prof in Funds.Where(x => (Project.Status.GuidanceAbout ?? new Guid[0]).Contains(x.ID)))
            {
                @prof.Name <br />
            }
        </fieldset>
        <!--guidance comments -->
        <fieldset class="chosenFields">
            <legend>Kommentarer til vejledning</legend>
            @Project.Status.GuidanceAboutText
        </fieldset>

        <!--demonstration chooser -->
        <fieldset class="chosenFields">
            <legend>Ansøgninger til</legend>

            @foreach (Fund prof in Funds.Where(x => (Project.Status.Financing ?? new Guid[0]).Contains(x.ID)))
            {
                @prof.Name <br />
            }
        </fieldset>
        <!--application comments-->
        <fieldset class="chosenFields">
            <legend>Kommentarer til ansøgning</legend>
            @Project.Status.FinancingText
        </fieldset>

        <!--demonstration chooser -->
        <fieldset class="chosenFields">
            <legend>Aktivitet</legend>
            @foreach (ProjectMeetingDemonstration prof in Demonstrations.Where(x => (Project.Status.DemonstrationIDs ?? new Guid[0]).Contains(x.ID)))
            {
                @prof.Name<br/>
            }
        </fieldset>
    </fieldset>
</div>

@*// ********************StatusStarted**********************@
<div class="formEntry open_hidden" id="Started">
    <br />
    <fieldset class="chosenFields">
        <legend>Startet</legend>
        <!--roles chooser -->
        <fieldset class="chosenFields">
            <legend>Roller</legend>
            @foreach (ProjectMeetingRole prof in Roles.Where(x => (Project.Status.Roles ?? new Guid[0]).Contains(x.ID)))
            {
                @prof.Name <br />
            }
        </fieldset>

        <!--financing chooser -->
        <fieldset class="chosenFields">
            <legend>Financiering</legend>
            @foreach (Fund prof in Funds.Where(x => (Project.Status.Financing ?? new Guid[0]).Contains(x.ID)))
            {
                @prof.Name <br/>                
            }
        </fieldset>
        <!--More Information -->
        <fieldset class="chosenFields">
            <legend>Yderligere information om financiering</legend>
            @Project.Status.FinancingText
        </fieldset>

    </fieldset>
</div>

@*    // ********************StatusCompleted**********************@
<div class="formEntry open_hidden" id="Completed">
    <br />
    <fieldset class="chosenFields">
        <legend>Færdigt</legend>

        <!--demonstration chooser -->
        <fieldset class="chosenFields">
            <legend>Gennemførte ting</legend>
            @foreach (ProjectMeetingDemonstration prof in Demonstrations.Where(x => (Project.Status.DemonstrationIDs ?? new Guid[0]).Contains(x.ID)))
            {
                @prof.Name <br/>
            }
        </fieldset>
    </fieldset>
</div>

@*// ********************R&D chooser*********************  *@
<fieldset class="chosenFields">
    <legend>R&D type</legend>
    <label>
        <input type="radio" name="StatusType" value="SwitchStatusNotRAndD" onclick=" toggleRD('NotRAndD'); "  @if (isRandD.HasValue && !isRandD.Value)
                                                                                                              {@Html.Raw("checked=\"checked\"")}>Non R&D</label>
    <label>
        <input type="radio" name="StatusType" value="SwitchStatusRAndD" onclick=" toggleRD('RAndD'); "  @if (isRandD.HasValue && isRandD.Value)
                                                                                                        {@Html.Raw("checked=\"checked\"")}>R&D</label>
</fieldset>

@*    // ********************StatusNotRAndD**********************@
<div class="formEntry open_hidden" id="NotRAndD">
    <br />
    <fieldset class="chosenFields">
        <legend>Non R&D</legend>
        <!--project type -->
        <fieldset class="chosenFields">
            <legend>Projekt Type</legend>
            @foreach (ProjectType ty in Types.Where(x => x.IsResearchAndDevelopment == false))
            {
                if (ty.ID == Project.Status.Type)
                {
                @ty.Name <br />
                }
            }

        </fieldset>
        <!--More Information -->
        <fieldset class="chosenFields">
            <legend>Yderligere information</legend>@if (isRandD.HasValue && !isRandD.Value)
                                                   {@Project.Status.Description}
        </fieldset>

    </fieldset>
</div>

@*// ********************StatusRAndD**********************@
<div class="formEntry open_hidden" id="RAndD">
    <br />
    <fieldset class="chosenFields">
        <legend>R&D</legend>
        <!--project type -->
        <fieldset class="chosenFields">
            <legend>Projekt Type</legend>
            @foreach (ProjectType ty in Types.Where(x => x.IsResearchAndDevelopment))
            {
                if (ty.ID == Project.Status.Type)
                {
                    @ty.Name<br/>
                }
            }
        </fieldset>
        <!--More Information -->
        <fieldset class="chosenFields">
            <legend>Yderligere information</legend>@if (isRandD.HasValue && isRandD.Value)
                                                   {@Project.Status.Description}
        </fieldset>
    </fieldset>
</div>

@*// ********************StatusPatents**********************@

<!--patent name -->
<fieldset class="chosenFields">
    <legend>Patent navn</legend>
    @Project.Status.PatentName
</fieldset>

